clear
set matsize 11000

********************************************************************************
* Read-in panel bloomberg data
use "./data/fomc_panel_b", clear

label var mpu10_2day "mpu"

******CREATE VARIABLES FOR TABLE 9*****
foreach v in ex_rate_regime us_integ trade_open ka_open fin_depth dollar_exp dollar_debt vuln_index int_diff_3m int_diff_3m_chg {

*Step 1: Standardize each exposure variable, i.e. subtract mean and divide by std. dev.

	sum `v' 
	gen `v'_std = (`v' - r(mean)) / r(sd)
	
*Step 2: Construct a logistic transformation of the standardized variable

	gen `v'_log =  exp(`v'_std) / (1 + exp(`v'_std))
	
*Step 3: Re-center the logistic variable in terms of distance between 25th and 75th percentiles

	sum `v'_log, detail
	gen `v'_exposure = (`v'_log - r(p25)) / (r(p75) - r(p25))
	

*Step 4: Construct interaction term with shocks

	gen `v'_mps_int = `v'_exposure * mps_2day
	
	gen `v'_mpu_int = `v'_exposure * mpu_2day

}	 

*Drop U.S.
drop if ccode==49


********************************************************************************
***Table A.10: Understanding the cross-country heterogeneity of asset price responses:
* 			 Emerging countries with dollar debt exposure
********************************************************************************

local replace replace 

*For robustness, can change variable ordering with loops
foreach y in yield2y yield10y {	
	
	foreach a in trade_open {

	foreach b in ka_open {
		 
	foreach c in ex_rate_regime {
			
	foreach d in dollar_debt {
				
	foreach e in int_diff_3m_chg { 
	
	preserve
	
		*Keep emerging countries only
		keep if advanced==0

		keep if `y'_2day!=. & `a'!=. & `b'!=. & `c'!=. & `d'!=. & `e'!=. & fin_depth!=.
				
			*First Variable
			quietly: reg `a'_mps_int mps_2day mpu_2day
			predict `a'_mps_orthog, residual

			quietly: reg  `a'_mpu_int mps_2day mpu_2day `a'_mps_orthog
			predict `a'_mpu_orthog, residual
			
			*Second Variable
			quietly: reg `b'_mps_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog
			capture predict `b'_mps_orthog, residual

			quietly: reg  `b'_mpu_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog
			capture predict `b'_mpu_orthog, residual
				
			*Third Variable
			quietly: reg `c'_mps_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog `b'_mpu_orthog
			capture predict `c'_mps_orthog, residual

			quietly: reg  `c'_mpu_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog `b'_mpu_orthog `c'_mps_orthog
			capture predict `c'_mpu_orthog, residual
			
			*Fourth Variable
			quietly: reg `d'_mps_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog `b'_mpu_orthog `c'_mps_orthog `c'_mpu_orthog
			capture predict `d'_mps_orthog, residual

			quietly: reg  `d'_mpu_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog `b'_mpu_orthog `c'_mps_orthog `c'_mpu_orthog `d'_mps_orthog
			capture predict `d'_mpu_orthog, residual
					
			*Fifth Variable
			quietly: reg `e'_mps_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog `b'_mpu_orthog `c'_mps_orthog `c'_mpu_orthog `d'_mps_orthog `d'_mpu_orthog
			capture predict `e'_mps_orthog, residual

			quietly: reg  `e'_mpu_int mps_2day mpu_2day `a'_mps_orthog `a'_mpu_orthog `b'_mps_orthog `b'_mpu_orthog `c'_mps_orthog `c'_mpu_orthog `d'_mps_orthog `d'_mpu_orthog `e'_mps_orthog
			capture predict `e'_mpu_orthog, residual

			************* REGRESSIONS ***********************************
			*Baseline Ordering
			local mps_int "`a'_mps_orthog `b'_mps_orthog `c'_mps_orthog `d'_mps_orthog `e'_mps_orthog"
			local mpu_int "`a'_mpu_orthog `b'_mpu_orthog `c'_mpu_orthog `d'_mpu_orthog `e'_mpu_orthog"
			
			capture quietly: reghdfe `y'_2day_std mps_2day `mps_int' mpu_2day `mpu_int', noabsorb cluster(ccode time)
			capture outreg2 using "tables\tableA10.xml", `replace' se bdec(3) bracket e(r2_a) label 

			*capture eststo 
							
		restore

	}
	}
	}
	}
	}

	local replace append

}
